<template>
	<view>
		
		<u-navbar :border-bottom="false" title="基础功能测试"></u-navbar>
		
		<view class="content">
			<!-- 正文内容 -->
			<view class="box">
				<view @click="goSetUser">
					保存用户信息
				</view>
				<view @click="goGetUser">
					获取用户信息到vuex
				</view>
				<view @click="goRemoveStorage">
					删除全部储存
				</view>
				<view @click="goSetToken">
					设置token
				</view>
				<view @click="goGetToken">
					获取token
				</view>
				<view @click="goRemoveToken">
					删除token
				</view>
				<view @click="goGetRequest">
					请求接口
				</view>
				<view @click="goVuex">
					查看vuex
				</view>
				<view @click="goUrl">
					提示公共url
				</view>
			</view>

			<view>
				接口数据：{{info}}
			</view>

		</view>
	</view>
</template>

<script>
	import {
		apiUrl
	} from "@/config"; //接口地址
	
	import {
		mapMutations,
		mapActions
	} from 'vuex'
	
	export default {
		data() {
			return {
				info: []
			}
		},
		methods: {
			...mapMutations([
				'login', // 将 `this.login()` 映射为 `this.$store.commit('login')`
				'delStorage',
				'setToken',
				'getToken',
				'removeToken'
			]),
			...mapActions(['testData']),
			goSetUser() {
				uni.setStorageSync("userinfo", "我是用户信息");
			},
			goGetUser() {
				this.login()
			},
			goRemoveStorage() {
				this.delStorage()
			},
			goSetToken() {
				this.setToken("123456")
			},
			goGetToken() {
				console.log(this.$store.getters.getToken(1))
			},
			goRemoveToken() {
				this.removeToken()
			},
			goGetRequest() {

				this.testData().then(res => { //方法一
					this.info = res.data
					console.log(res);
				}).catch(err => {
					console.log(err);
				})

				// this.$store.dispatch('testData').then(res => {  //方法二
				// 	this.info = res.data
				// }).catch(err => {
				// 	console.log(err)
				// })

			},
			goVuex() {
				console.log(this.$store.state.publicModule.userinfo)
			},
			goUrl() {
				this.$_tishi(apiUrl)
			}
		}
	}
</script>

<style lang="less" scoped>
	.box {
		display: flex;
		flex-wrap: wrap;

		view {
			padding: 20upx;
			border: 1upx solid #333333;
			margin: 20upx;
		}
	}
</style>
